<template>
  <div class="input-config">
    <div class="grid grid-cols-1 gap-4">
      <div>
        <label class="block text-sm font-medium text-gray-700 mb-1">输入值</label>
        <el-input
          v-model="localStep.value"
          placeholder="要输入的文本内容"
          size="small"
          @change="updateStep"
        >
          <template #prepend>
            <el-icon><i-ep-edit /></el-icon>
          </template>
        </el-input>
      </div>
      
      <div class="border-t border-gray-200 pt-4">
        <h4 class="text-sm font-medium text-gray-700 mb-3">输入选项</h4>
        <div class="grid grid-cols-2 gap-3">
          <el-checkbox 
            v-model="localStep.clearBeforeInput"
            @change="updateStep"
          >
            先清除现有内容
          </el-checkbox>
          <el-checkbox 
            v-model="localStep.pressEnterAfterInput"
            @change="updateStep"
          >
            输入后按回车键
          </el-checkbox>
          <el-checkbox 
            v-model="localStep.selectAllBeforeInput"
            @change="updateStep"
          >
            输入前全选文本
          </el-checkbox>
          <el-checkbox 
            v-model="localStep.focusBeforeInput"
            @change="updateStep"
          >
            输入前聚焦元素
          </el-checkbox>
        </div>
      </div>
      
      <div class="grid grid-cols-2 gap-3">
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">输入速度 (ms/字符)</label>
          <el-input-number
            v-model="localStep.typingDelay"
            :min="0"
            :step="10"
            size="small"
            class="w-full"
            @change="updateStep"
          />
        </div>
        
        <div>
          <label class="block text-sm font-medium text-gray-700 mb-1">输入后等待 (ms)</label>
          <el-input-number
            v-model="localStep.delay"
            :min="0"
            :step="100"
            size="small"
            class="w-full"
            @change="updateStep"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'
import { Edit as iEpEdit } from '@element-plus/icons-vue'

const props = defineProps({
  step: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['update'])

const localStep = ref({
  value: '',
  clearBeforeInput: false,
  pressEnterAfterInput: false,
  selectAllBeforeInput: false,
  focusBeforeInput: true,
  typingDelay: 50,
  delay: 1000,
  ...props.step
})

watch(() => props.step, (newStep) => {
  localStep.value = {
    value: '',
    clearBeforeInput: false,
    pressEnterAfterInput: false,
    selectAllBeforeInput: false,
    focusBeforeInput: true,
    typingDelay: 50,
    delay: 1000,
    ...newStep
  }
}, { deep: true })

const updateStep = () => {
  emit('update', localStep.value)
}
</script>